package com.mxdx.edu.controller;


import com.alibaba.fastjson.JSONObject;
import com.mxdx.edu.common.ApiResult;
import com.mxdx.edu.common.CommonUtils;
import com.mxdx.edu.common.log.AppLogger;
import com.mxdx.edu.enums.ErrorEnums;
import com.mxdx.edu.model.StudentScore;
import com.mxdx.edu.service.*;
import com.mxdx.edu.util.ServletUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;

/**
 * 学生费用controller
 * @author howie
 */
@Controller
@RequestMapping(value = "/fee")
public class StudentTuitionController extends BaseController{

	private AppLogger logger = new AppLogger(StudentTuitionController.class);

	@Resource
	private IStudentTuitionService studentTuitionService;

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/auth/student")
	public ModelAndView fee(HttpServletRequest request) {
		logger.entry(ServletUtil.getClientIp(request), "fee");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		ModelAndView result = new ModelAndView("/h5/studentFee");
		List<Map<String, Object>> feeList = new ArrayList<>();
		String studentName = "";
		String headPortrait = "";
		String mood = "";
		try{
			Map<String,Object> userMap = getStudentMap(request);
			String studentId = CommonUtils.getStrValueFromMap(userMap,"studentId","");
			studentName = CommonUtils.getStrValueFromMap(userMap, "studentName", "");
			mood = CommonUtils.getStrValueFromMap(userMap, "mood", "");

			Map<String,Object> map = new HashMap<>();

			map.put("studentId",studentId);

			feeList = studentTuitionService.findStudentTuitionList(map);
			logger.info(ServletUtil.getClientIp(request));
		}catch (Exception e){
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("feeList", feeList);
		result.addObject("studentName", studentName);
		result.addObject("headPortrait", headPortrait);
		result.addObject("mood", mood);

		return result;
	}

}
